<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="created" content="2018-10-23T06:18:10.521000000">
    <meta name="changed" content="2018-10-23T06:18:42.262000000">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="en">
    <title>
      Testing multiple files
    </title>
    <link rel="stylesheet" type="text/css" href="../../style.css">
  </head>
  <body>
    <div class="maindiv">
      <h1>
        Testing multiple files
      </h1>
      <p>
        In the classroom example, you will have many files that you wish to test for their equivalence, and you won't want to read the output for each of the student's solutions.
      </p>
      <h2>
        Building comparison into the circuit
      </h2>
      <p>
        One approach is to build a test circuit that does the comparison directly. Here, we create an additional circuit within the testing file that contains our solution circuit. In our overall testing circuit, we include both the subcircuit from <tt><b>master.circ</b></tt> and the subcircuit from the solution circuit located directly into the nested circuit. We wire it so that there is just one output, which is 1 as long as the two subcircuits agree.
      </p>
      <blockquote>
        <img src="../../../../img-guide/verify-adder-test2.png" alt="#########">
      </blockquote>
      <p>
        Now we can simply run Logisim substituting each query file. For any correct solution, the only output will be "1".
      </p>
      <h2>
        Using redirection and shell scripts
      </h2>
      <p>
        If you're quite comfortable with the command line, you can build your own shell script to accomplish this. Here, we'll use redirection (the &gt; operator) to save the output of each circuit into a file. For instance, we might issue the following two commands to collect the output of the master circuit and the query circuit.
      </p>
      <blockquote>
         <div class=forcode>
          <tt>java -jar logisim-evolution.jar test.circ -tty table &gt; out-master.txt</tt>
        </div>
        <div class=forcode>
          <tt>java -jar logisim-evolution.jar test.circ -tty&nbsp;table -sub master.circ query.circ &gt; out-query.txt</tt>
        </div>
      </blockquote>
      <p>
        Now we've created two different files. We can then compare the two output files using a program built for that purpose. Under Linux or MacOS X, you might want to use the <b>cmp</b> or <b>diff</b> command-line utilities. Under Windows, you might want to use command-line utilities <b>fc</b> or WinMerge.
      </p>
      <p>
        To process several query files, you would like want to build a simple program such as a shell script to iterate through each and comparing the output. Here is how I would do it under Linux's <b>bash</b>:
      </p>
      <blockquote>
        <tt>RUN_TEST="java&nbsp;-jar&nbsp;logisim-filename.jar&nbsp;adder-test.circ&nbsp;-tty&nbsp;table"<br>
        ${RUN_TEST}&nbsp;&gt;&nbsp;output-master.txt<br>
        for&nbsp;QUERY_FILE&nbsp;in&nbsp;query*.circ<br>
        do<br>
        &nbsp;&nbsp;if&nbsp;${RUN_TEST}&nbsp;-sub&nbsp;^master.circ&nbsp;${QUERY_FILE}&nbsp;|&nbsp;cmp&nbsp;-s&nbsp;output-master.txt<br>
        &nbsp;&nbsp;then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"${QUERY_FILE}&nbsp;OK"<br>
        &nbsp;&nbsp;else<br>
        &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"${QUERY_FILE}&nbsp;different"<br>
        &nbsp;&nbsp;fi<br>
        done</tt>
      </blockquote>
      <p>
        <b>Next:</b> <a href="test.html">Test Vector</a>.
      </p>
    </div>
  </body>
</html>
